"use client"; import { getWheelApi } from "@/api/cashWheel"; import { ServiceTypes } from "@/api/customservice"; import { userInfoApi } from "@/api/login"; import { lredPacketApi, redPacketApi } from "@/api/promo"; import { getGiveInfoApi } from "@/api/slots"; import UserRecharge, { ModalRefProps, Timeout } from "@/components/ModalPopup/RechargeModal"; import RedPacketModal, { RedPacketModalProps } from "@/components/ModalPopup/RedPacketModal"; import SignInModal, { SignInModalProps } from "@/components/ModalPopup/SignInModal"; import SlotsModal, { SlotModalRefProps } from "@/components/ModalPopup/SlotsModal"; import WheelModal, { WheelModalProps } from "@/components/ModalPopup/WheelModal"; import { useEventPoint } from "@/hooks/useEventPoint"; import { Link } from "@/i18n/routing"; import { useModalShow } from "@/stores/modalShow"; import { useFirstPayStore } from "@/stores/useFirstPayStore"; import { useGlobalNoticeStore } from "@/stores/useGlobalNoticeStore"; import { useSignStore } from "@/stores/useSignStore"; import useWheelStore from "@/stores/useWheelStore"; import { getToken } from "@/utils/Cookies"; import { useRequest } from "ahooks"; import { Badge } from "antd-mobile"; import dayjs from "dayjs"; import { useTranslations } from "next-intl"; import Image from "next/image"; import { usePathname } from "next/navigation"; import { FC, useEffect, useMemo, useRef, useState } from "react"; interface Props { services: ServiceTypes[]; } interface SlotSectionProps { onDestory?: () => void; } /** * 免费送活动 */ const SlotSection: FC = ({ onDestory }) => { const slotsRef = useRef(null); const getSlots = async () => { const token = getToken(); if (token) { const result = await getGiveInfoApi(); return result.data; } else { destory(); return Promise.resolve({}); } }; const { data: slots, run: slotRun } = useRequest(getSlots, { pollingInterval: 2000, pollingErrorRetryCount: 1, pollingWhenHidden: false, }); const slotHandler = () => { slotsRef.current?.onOpen(slots); }; const destory = () => { if (onDestory && typeof onDestory === "function") onDestory(); }; return ( <> {slots?.id ? ( ) : null} {/*随机送*/} ); }; /** * 轮盘 */ const WheelSection = () => { const pathname = usePathname(); const wheelModalRef = useRef(null); const [data, setData] = useState([]); const { modalShow, closeModalShow } = useModalShow((state: any) => ({ modalShow: state.modalShow, closeModalShow: state.closeModalShow, })); const keyName = useMemo(() => { return "WheelSection"; }, []); const { wheelStatus, wheelCurrent, setWheel } = useWheelStore((state) => ({ wheelStatus: state.status, wheelCurrent: state.currentWheel, setWheel: state.setWheel, })); useEffect(() => { setWheel().then((data) => { if (data && useWheelStore.getState().status === 1) { setData(data); } }); }, []); useEffect(() => { if (!data) return; if (modalShow === keyName) { wheelModalRef.current?.onOpen(data); } }, [modalShow, data, keyName, pathname]); const destoryComponent = () => { if (modalShow === keyName) { closeModalShow(keyName); } }; return ( <> {wheelStatus === 2 ? ( {"wheel"} ) : null} {/* 轮盘弹窗 */} ); }; /** * 首充 */ const PaySection = () => { const token = getToken(); const { firstPay, getPayData } = useFirstPayStore((state) => { return { firstPay: state.first_pay, getPayData: state.getPayData, }; }); const userRechargeRef = useRef(null); // 首充活动 // const getPayInfo = async (): Promise => { // if (token) { // const result = await getPaysApi(); // return result.data; // } else { // return Promise.resolve({ // first_pay: [], // pay: [], // }); // } // }; // const getPayInfo = async (): Promise => {}; const { data, run: payRun } = useRequest(getPayData, { pollingErrorRetryCount: 1, pollingWhenHidden: false, }); return ( <> {firstPay.map((item, index) => { return (
{ userRechargeRef.current?.onOpen && userRechargeRef.current?.onOpen(firstPay, index); }} /> {item.count_down > 0 ? ( ) : null}
); })} {/*首充弹窗*/} ); }; /** * 红包雨 */ const RedPacketSection = () => { const token = getToken(); const redPacketModalRef = useRef(null); const getRedPacketInfo = async () => { try { let redPacketInfo: any; let actList: any = []; if (token) { redPacketInfo = await lredPacketApi(); actList = redPacketInfo.data?.red_packets || []; } else { redPacketInfo = await redPacketApi(); actList = redPacketInfo.data || []; } // 已经开始 return actList.filter((aItem: any) => { return aItem.is_start; }); } catch (error) {} }; // 红包雨轮询 const { data: packets, run } = useRequest(getRedPacketInfo, { pollingInterval: 5000, pollingErrorRetryCount: 1, pollingWhenHidden: false, }); return ( <> {packets?.map((item, index) => { const icons = JSON.parse(item.icon); const icon = icons[icons.length - 1]; return (
{ redPacketModalRef.current?.onOpen(packets, index); }} />
); })} {/*红包雨弹窗*/} ); }; const MessageSection = () => { const { unread, userUnred } = useGlobalNoticeStore((state) => ({ unread: state.unread, userUnred: state.userUnred, })); return ( <> {unread || userUnred ? ( ) : null} ); }; /** * 客服 */ const CustomerSection: FC> = (props) => { const { services } = props; const defaultService = services?.filter((item) => item.is_suspend === 1); return ( <> {defaultService?.map((item, index) => ( {""} ))} ); }; const getMaxSignId = (obj: any) => { if (!obj) return null; const signArr: number[] = []; Object.keys(obj).map((key) => { if (obj[key] === 9) { signArr.push(Number(key)); } }); return signArr.length > 0 ? Math.max(...signArr) : null; }; /** * 签到活动 */ const SignInSection: FC = () => { const { modalShow, closeModalShow } = useModalShow((state: any) => ({ modalShow: state.modalShow, closeModalShow: state.closeModalShow, })); const SignInRef = useRef(null); const [activityId, setActivityId] = useState(null); const keyName = "SignInSection"; const { getSignData, signData } = useSignStore((state) => { return { getSignData: state.getSignData, signData: state.signData, }; }); const getUserInfo = async () => { const res: any = await userInfoApi(); if (res.code === 200 && res.data?.activity) { const activity_id = getMaxSignId(res.data?.activity); if (activity_id) { setActivityId(activity_id); await getSignData({ activity_id: activity_id }); } } }; const checkIsShowed = () => { const showTime = localStorage.getItem("sign"); if (showTime) { const nextDay = dayjs(Number(showTime)).add(1, "day").format("YYYY-MM-DD"); if (dayjs(nextDay).isAfter(dayjs())) { return true; } } return false; }; useEffect(() => { // if (checkIsShowed()) return; if (getToken()) getUserInfo(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const destoryComponent = () => { closeModalShow(keyName); }; useEffect(() => { console.log(modalShow, modalShow === keyName, getToken()); if (modalShow === keyName && getToken()) { if (checkIsShowed()) { destoryComponent(); } else { localStorage.setItem("sign", `${Date.now()}`); signInHandle(); } } // eslint-disable-next-line react-hooks/exhaustive-deps }, [modalShow, keyName]); const signInHandle = () => { SignInRef.current?.onOpen(); }; if (!activityId) { return null; } return ( <> {/*
Sign
*/} ); }; const ServiceWidget: FC = (props) => { const { services } = props; const [type, setType] = useState(0); const { eventView } = useEventPoint(); const newServices = services?.filter((item) => item.status === 1) || []; const getWheel = () => { if (!getToken()) return Promise.resolve(undefined); return getWheelApi().then((res) => { return res.data; }); }; useEffect(() => { // 数据存储,侧边栏使用 // setSocials(socials); // pixel 埋点 // eventView(); }, []); const t = useTranslations("HomePage"); // const servicesMap = new Map([ // [ // 0, // { // components: , // }, // ], // [ // 1, // { // components: , // }, // ], // [ // 2, // { // components: , // }, // ], // [ // 3, // { // components: , // }, // ], // [ // 4, // { // components: , // }, // ], // [ // 5, // { // components: , // }, // ], // [ // 6, // { // components: , // }, // ], // ]); // const curComponents = useMemo(() => { // return servicesMap.get(type)?.components; // // eslint-disable-next-line react-hooks/exhaustive-deps // }, [type, services, servicesMap]); // const modalDestory = () => { // setType(type + 1); // }; // console.log("type:", type); return ( <>
{/* {React.cloneElement(curComponents, { onDestory: modalDestory })} */} {/*轮盘 */} {/*首充*/} {/* 红包雨icon */} {/*未读消息*/} {/*客服*/} {/* 签到 */}
= 5 ? 5 : (newServices?.length ?? 1)},1fr)`, }} > {newServices.map((service, index) => { return ( ); })}
{t("Service")}
{/*share*/}
{t("Share")}
{"BCWIN777"} ); }; export default ServiceWidget;